<template>
  <div class="info">
    <div class="M_avator">
      <div>
        <van-popover
          v-model="showPopover"
          trigger="click"
          placement="right-start"
        >
          <!-- 点击头像要显示的东西 -->
          <van-cell title="我的头像" size="large">
            <template #title>
              <div class="M_avator">
                <img :src="info.avator" width="50px" height="50px" />
                <div style="padding-left:2vw">
                  <p class="nickName">{{ info.nickname }}</p>
                  <van-tag plain type="primary">{{info.Class}}</van-tag>
                </div>
                
              </div>
              <van-cell title="ta的校友圈" is-link @click="handlePrefer" style="padding:1vh 0;font-size:12px"/>
              <van-button type="info" icon="plus" size="mini" @click="addFriend">添加好友</van-button>
            </template>
          </van-cell>
          <template #reference>
            <img :src="info.avator" width="50px" height="50px" />
          </template>
        </van-popover>
      </div>
      <div style="margin-left: 10px; flex-grow: 1">
        <p class="nickName">{{ info.nickname }}</p>
        <p class="time">{{ info.releasedTime }}</p>
      </div>
      <div style="color:red;font-size:18px">￥{{info.price}}</div>
    </div>
    <div class="content">
      
      <div style="display:flex">
        <van-uploader
          v-model="this.fileList"
          :show-upload="false"
          :deletable="false"
        />
        <div class="content_words">{{ info.content }}</div>
      </div>
    </div>
  </div>
</template>

<script>
import { timestampToTime } from "@/utils/timeStamp";
export default {
  props: ["pieceData"],
  data() {
    return {
      info: this.pieceData,
      fileList: [],
      showPopover: false,
    };
  },
  created() {
    if (this.info.fileList) {
      let arr = this.info.fileList.split(";");
      this.fileList.push({ url: `${arr[0]}` });
    }
    this.info.releasedTime = timestampToTime(this.info.time);
  },
  methods: {
    // 添加好友
    addFriend(){
      let userID=this.$store.state.userInfo.userID||localStorage.getItem("userID")
      this.$axios.post('/saveFriend',{'friendID':this.info.userID,'userID':userID})
    },
    // ta的校友圈
    handlePrefer(){
      this.$router.push({
        path: "/prefer",
        query: { "origin": "released", "userID": localStorage.getItem('userID') },
      });
    }
  },
};
</script>

<style scoped>
.M_avator {
  display: flex;
  text-align: left;
}
.content {
  text-align: left;
}

.nickName {
  margin: 0;
  color: #0b1994;
  text-align: left;
  line-height: 20px;
  font-size: 18px;
  font-weight: bold;
}
.time {
  margin-top: 5px;
  margin-bottom: 0;
}
.content_words {
  text-align: left;
  padding: 10px;
  color: gray;
}

.operate {
  display: flex;
}
.operate div {
  flex: 1;
}
.comments p {
  margin: 5px 0;
}
.comments span {
  font-weight: bold;
}
.price{
  text-align: right;
  font-size: 18px;
  color: red;padding: 0 10px;
}
</style>